package com.basic.common.security;

import com.basic.common.string.StringOperationDsUtil;
import org.apache.commons.lang3.StringUtils;

/**
 * 脱敏
 *
 * @author YanShuang
 * @version v_1.0.1
 * @since 2019/2/27 16:42
 */
public class SensitiveWordsDsUtil {

    /**
     * 用户名
     *
     * @param userName
     * @return
     */
    public static String userName(String userName) {
        return StringUtils.left(userName, 1).concat("****");
    }

    /**
     * 姓名
     * @param realName
     * @return
     */
    public static String realName(String realName) {
        return StringUtils.left(realName, 1).concat("**");
    }

    /**
     * 手机号
     *
     * @param mobilePhone
     * @return
     */
    public static String mobilePhone(String mobilePhone) {
        return StringOperationDsUtil.around(mobilePhone, 3, 4);
    }

    /**
     * 邮箱
     *
     * @param email
     * @return
     */
    public static String email(String email) {
        if (StringUtils.isBlank(email)) {
            return "";
        }
        int index = StringUtils.indexOf(email, "@");
        if (index <= 1) {
            return email;
        } else {
            return StringUtils.rightPad(StringUtils.left(email, 1), index, "*").concat(StringUtils.mid(email, index, StringUtils.length(email)));

        }
    }

    /**
     * 银行卡
     *
     * @param bankCardNo
     * @return
     */
    public static String bankCardNo(String bankCardNo) {
        return StringOperationDsUtil.right(bankCardNo, 4);
    }

    /**
     * 身份证
     *
     * @param cardNo
     * @return
     */
    public static String idCardNo(String cardNo) {
        return StringOperationDsUtil.around(cardNo, 6, 4);
    }

    public static void main(String[] args) {
        System.out.println(userName("思念对方"));
        System.out.println(realName("思念对方"));
        System.out.println(mobilePhone("13500000001"));
        System.out.println(bankCardNo("12345678912345"));
        System.out.println(idCardNo("232332198909082414"));
    }

}
